package com.ruoyi.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsOutboundRecord;
import com.ruoyi.wms.service.IWmsOutboundRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 出库记录Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Api(tags = "出库记录管理")
@RestController
@RequestMapping("/wms/outbound/record")
public class WmsOutboundRecordController extends BaseController
{
    @Autowired
    private IWmsOutboundRecordService wmsOutboundRecordService;

    /**
     * 查询出库记录列表
     */
    @ApiOperation("查询出库记录列表")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsOutboundRecord wmsOutboundRecord)
    {
        startPage();
        List<WmsOutboundRecord> list = wmsOutboundRecordService.selectWmsOutboundRecordList(wmsOutboundRecord);
        return getDataTable(list);
    }

    /**
     * 根据出库单ID查询出库记录列表
     */
    @ApiOperation("根据出库单ID查询出库记录列表")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:list')")
    @GetMapping("/order/{orderId}")
    public AjaxResult listByOrderId(@PathVariable("orderId") Long orderId)
    {
        List<WmsOutboundRecord> list = wmsOutboundRecordService.selectWmsOutboundRecordByOrderId(orderId);
        return success(list);
    }

    /**
     * 根据明细ID查询出库记录列表
     */
    @ApiOperation("根据明细ID查询出库记录列表")
    @ApiImplicitParam(name = "detailId", value = "出库单明细ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:list')")
    @GetMapping("/detail/{detailId}")
    public AjaxResult listByDetailId(@PathVariable("detailId") Long detailId)
    {
        List<WmsOutboundRecord> list = wmsOutboundRecordService.selectWmsOutboundRecordByDetailId(detailId);
        return success(list);
    }

    /**
     * 根据分配ID查询出库记录列表
     */
    @ApiOperation("根据分配ID查询出库记录列表")
    @ApiImplicitParam(name = "allocationId", value = "库存分配ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:list')")
    @GetMapping("/allocation/{allocationId}")
    public AjaxResult listByAllocationId(@PathVariable("allocationId") Long allocationId)
    {
        List<WmsOutboundRecord> list = wmsOutboundRecordService.selectWmsOutboundRecordByAllocationId(allocationId);
        return success(list);
    }

    /**
     * 导出出库记录列表
     */
    @ApiOperation("导出出库记录列表")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:export')")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsOutboundRecord wmsOutboundRecord)
    {
        List<WmsOutboundRecord> list = wmsOutboundRecordService.selectWmsOutboundRecordList(wmsOutboundRecord);
        ExcelUtil<WmsOutboundRecord> util = new ExcelUtil<WmsOutboundRecord>(WmsOutboundRecord.class);
        util.exportExcel(response, list, "出库记录数据");
    }

    /**
     * 获取出库记录详细信息
     */
    @ApiOperation("获取出库记录详细信息")
    @ApiImplicitParam(name = "recordId", value = "出库记录ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(wmsOutboundRecordService.selectWmsOutboundRecordById(recordId));
    }

    /**
     * 新增出库记录
     */
    @ApiOperation("新增出库记录")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:add')")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsOutboundRecord wmsOutboundRecord)
    {
        return toAjax(wmsOutboundRecordService.insertWmsOutboundRecord(wmsOutboundRecord));
    }

    /**
     * 修改出库记录
     */
    @ApiOperation("修改出库记录")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:edit')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsOutboundRecord wmsOutboundRecord)
    {
        return toAjax(wmsOutboundRecordService.updateWmsOutboundRecord(wmsOutboundRecord));
    }

    /**
     * 删除出库记录
     */
    @ApiOperation("删除出库记录")
    @ApiImplicitParam(name = "recordIds", value = "出库记录ID数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:record:remove')")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(wmsOutboundRecordService.deleteWmsOutboundRecordByIds(recordIds));
    }
}